package cn.smart.epic.modular.system.controller;

import cn.smart.epic.common.controller.BaseController;
import cn.smart.epic.common.node.VTreeNode;
import cn.smart.epic.common.persistence.dao.MenuMapper;
import cn.smart.epic.core.util.CommonUtil;
import cn.smart.epic.core.util.ToolUtil;
import cn.smart.epic.modular.system.service.IMenuService;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther Uncle_Z
 * @date 2018/8/30 19:26
 * @Email:2545375@qq.com
 * @Descrition
 * @since 1.0
 */

@Api(value = "/menu", tags = "菜单管理")
@RestController
@RequestMapping(value = "/menu/")
public class MenuController extends BaseController {

    @Resource
    private MenuMapper menuMapper;

    @Resource
    private IMenuService menuService;

    @GetMapping(value = "menuTreeListByRoleId/{roleId}")
    public JSONObject menuTreeListByRoleId(@PathVariable Integer roleId){
        List<Integer> menuIds = menuMapper.getMenuIdsByRoleId(roleId);
        if (ToolUtil.isEmpty(menuIds)) {
            List<VTreeNode> menuTreeList = menuMapper.menuTreeList();
            return CommonUtil.successJson(menuTreeList);
        }else{
            List<VTreeNode> menuTreeList = menuMapper.menuTreeListByRoleId(menuIds);
            return CommonUtil.successJson(menuTreeList);
        }
    }

}
